feat: EXPIREAT, PEXPIREAT, GETSET, MSETNX, LPOP/RPOP count - #318
Merged
Conversation
adds six commands that round out common string and list operations: - EXPIREAT key timestamp — set expiry at an absolute unix timestamp (secs) - PEXPIREAT key timestamp-ms — same but in milliseconds - GETSET key value — atomically get the old value and set a new one; clears any existing ttl - MSETNX key value [...] — set multiple keys only if none of them already exist (all-or-nothing) - LPOP key [count] — without count returns a bulk string; with count returns an array - RPOP key [count] — same semantics as LPOP with count implementation notes: - EXPIREAT/PEXPIREAT convert unix epoch to ember's internal monotonic clock via a new unix_ms_to_monotonic_ms() helper (inverse of the existing monotonic_to_unix_ms) - both functions share a ClockAnchor captured at process start for coherent round-trips - EXPIREAT is persisted to AOF as Pexpireat (absolute ms); recovery converts to remaining TTL - MSETNX uses a two-phase fan-out: check existence across all shards, then write all pairs if none exist. mirrors redis cluster semantics where MSETNX pairs must share a hash slot - LPOP/RPOP count uses separate shard request variants (LPopCount/RPopCount) to keep the response type distinct (array vs bulk string) without adding conditional logic on the hot path 577 unit tests pass; 12 new integration tests added
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
summary
adds six commands that fill in the remaining gaps in common string and list operations:
what was tested
cargo test -p emberkv-core)cargo test -p ember-protocol)expireat_sets_absolute_expiry,expireat_missing_key_returns_zeropexpireat_sets_absolute_expiry_msgetset_returns_old_value,getset_missing_key_returns_nilmsetnx_all_new_returns_one,msetnx_any_existing_returns_zero_and_no_changeslpop_no_count_returns_bulk_string,lpop_count_returns_array,lpop_count_exceeding_list_returns_allrpop_count_returns_arraycargo clippy -D warningsclean on all affected cratesdesign notes
EXPIREAT/PEXPIREAT time model: ember stores expiry as a monotonic ms offset from process start, not unix epoch. a new
unix_ms_to_monotonic_ms()function provides the inverse of the existingmonotonic_to_unix_ms(), sharing a singleClockAnchorcaptured at startup so both conversions are coherent. EXPIREAT is persisted to AOF asPexpireat(absolute unix ms); on recovery the remaining TTL is computed from wall time at that instant.MSETNX fan-out: unlike MSET (which fans out individual
Setrequests), MSETNX needs to check all keys before writing any. we do two passes viaroute_multi: firstExistsacross all shards, thenSetfor each pair if all were absent. this is not atomic across shards in the same way redis isn't atomic across hash slots in cluster mode, but it is correct for single-node and cluster-mode when keys share a slot.LPOP/RPOP count dispatch:
count=Nonereuses the existingLPop/RPopshard variants (returningShardResponse::Value) whilecount=Some(n)uses newLPopCount/RPopCountvariants (returningShardResponse::Array). this keeps the no-count path zero-overhead and avoids any conditional branching in the hot path.